package com.ht.shortlink.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ht.shortlink.project.common.convention.result.Result;
import com.ht.shortlink.project.common.convention.result.Results;
import com.ht.shortlink.project.dto.req.ShortLinkStatsAccessRecordsGroupReqDTO;
import com.ht.shortlink.project.dto.req.ShortLinkStatsAccessRecordsReqDTO;
import com.ht.shortlink.project.dto.req.ShortLinkStatsGroupReqDTO;
import com.ht.shortlink.project.dto.req.ShortLinkStatsReqDTO;
import com.ht.shortlink.project.dto.resp.ShortLinkStatsAccessRecordsGroupRespDTO;
import com.ht.shortlink.project.dto.resp.ShortLinkStatsAccessRecordsRespDTO;
import com.ht.shortlink.project.dto.resp.ShortLinkStatsRespDTO;
import com.ht.shortlink.project.service.IShortLinkStatsService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 *  短链接监控服务层
 */
@RestController
@RequiredArgsConstructor
public class ShortLinkStatsController {
    private final IShortLinkStatsService shortLinkStatsService;

    /**
     *  单个短链接监控数据详情
     */
    @GetMapping("/api/short-link/v1/stats")
    public Result<ShortLinkStatsRespDTO> oneShortLinkStats(ShortLinkStatsReqDTO requestParam){
        return Results.success(shortLinkStatsService.oneShortLinkStats(requestParam));
    }

    /**
     *  分组查询短链接监控数据详情
     */
    @GetMapping("/api/short-link/v1/stats/group")
    public Result<ShortLinkStatsRespDTO> groupShortLinkStats(ShortLinkStatsGroupReqDTO requestParam){
        return Results.success(shortLinkStatsService.groupShortLinkStats(requestParam));
    }

    /**
     *  分页获取访问日志监控数据
     */
    @GetMapping("/api/short-link/v1/access-logs")
    public Result<IPage<ShortLinkStatsAccessRecordsRespDTO>> queryLinkStatsAccessRecords(ShortLinkStatsAccessRecordsReqDTO requestParam){
        return Results.success(shortLinkStatsService.queryLinkStatsAccessRecords(requestParam));
    }

    /**
     *  分页获取访问分组内短链接日志监控数据
     */
    @GetMapping("/api/short-link/v1/access-logs/group")
    public Result<IPage<ShortLinkStatsAccessRecordsGroupRespDTO>> queryLinkStatsAccessRecords(ShortLinkStatsAccessRecordsGroupReqDTO requestParam){
        return Results.success(shortLinkStatsService.queryGroupStatsAccessRecords(requestParam));
    }
}
